<!--
 * @Author: your name
 * @Date: 2021-08-03 13:36:05
 * @LastEditTime: 2021-08-12 13:26:42
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \getHome (2)\src\components\discounts\amend.vue
-->
<!--登录-->
<template>
  <div class="login">
    <header class="login-header">
      <img
        src="../../assets/logo.png"
        alt="logo"
        style="borderRadius: '25px'"
      />
      <h1>星福生活管理平台</h1>
    </header>
    <div class="login-content">
      <h2>用户登录</h2>
      <el-form ref="form" :model="form" label-width="60px">
        <el-form-item label="用户名">
          <el-input
            v-model="form.username"
            @keyup.enter.native="onSubmit"
            style="color: rgba(0,0,0,.25)"
          ></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input
            v-model="form.password"
            @keyup.enter.native="onSubmit"
            type="password"
            style="color: rgba(0,0,0,.25)"
          ></el-input>
        </el-form-item>
        <el-form-item style="width:100%;">
          <el-button
            style="background-color:#fd804c;color: #fff;width:100%;"
            @click="onSubmit"
            :loading="logining"
            >登录</el-button
          >
        </el-form-item>
      </el-form>

      <!-- <div id="u2617" class="ax_default" data-label="底部版权">
        <div id="u2619_text" style="color: rgba(0,0,0,.25), textAlign: right">
          <p>
            <span>CopyRight @ 星life 2021 - 2039</span>
          </p>
        </div>
      </div> -->
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      logining: false,

      form: {
        username: "",
        password: ""
      },
      rules2: {
        username: [
          {
            required: true,
            message: "请输入账号",
            trigger: "blur"
          }
        ],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }]
      }
    };
  },
  activated() {
    localStorage.setItem("key", ""); //尝试解决登录再某种情况下会带token问题
  },

  methods: {
    onSubmit() {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.logining = true;
          this.$http({
            url: `/memberadmin/mgr/backstage/user/login?userName=${this.form.username}&password=${this.form.password}`,
            method: "GET"
          }).then(res => {
            if (res.success == 1) {
              this.logining = false;
              localStorage.setItem("登录成功,,,,,,,,,,,,", res);
              localStorage.setItem("userScope", res.data.userScope);
              localStorage.setItem("key", res.data.token);
              localStorage.setItem("userName", res.data.userName);
              this.$message.success("登录成功");

              if (res.data.userScope == "bms") {
                this.$router.push({ path: "/authentication" });
              }
              if (res.data.userScope == "bms-rfull") {
                this.$router.push({ path: "/authentication" });
              } else if (res.data.userScope == "bms-rf") {
                this.$router.push({ path: "/authentication" });
              } else if (res.data.userScope == "hss-order") {
                this.$router.push({ path: "/ordersList" });
              } else if (res.data.userScope == "hss") {
                this.$router.push({ path: "/homeList" });
              }
            } else {
              //console.log(`登录dsdsd`);
              this.logining = false;
              this.$message.error(res.errorMsg);
            }
          });
        } else {
          this.$message.error(res.errorMsg);
          return false;
        }
      });
    }
  }
};
</script>
<style scoped lang="scss">
.content {
  top: 0 !important;
  padding-left: 0 !important;
  overflow-y: hidden !important;
}
.login {
  width: 100%;
  height: 100%;
  background-image: url("../../assets/bg.jpg");
  background-size: 100% 100%;

  .login-header {
    display: flex;
    align-items: center;
    height: 80px;
    background-color: rgba(21, 20, 13, 0.5);
    img {
      width: 40px;
      height: 40px;
      margin: 0 15px 0 50px;
    }

    h1 {
      display: inline-block;
      font-size: 32px;
      color: #fff;
      padding-top: 10px;
    }
  }

  .login-content {
    width: 300px;
    height: 280px;
    background-color: #fff;
    margin: 50px auto;
    padding: 20px 40px;
    h2 {
      text-align: center;
      font-size: 28px;
      font-weight: bold;
      margin-bottom: 28px;
    }
    .login-form {
      .login-form-button {
        width: 100%;
      }
    }
  }
}
</style>
